#ifndef SYNTAX_H
#define SYNTAX_H

#define ISTERMINAL  0
#define NOTERMINAL  1

#include "Lex.h"
#include "treeParse.h"
#include <QString>
#include <stdio.h>
#include <vector>
#include <set>

typedef enum
{
    Program, ProgramHead, ProgramName, DeclarePart,
    TypeDec, TypeDeclaration, TypeDecList, TypeDecMore,
    TypeId, TypeName, BaseType, StructureType,
    ArrayType, Low, Top, RecType,
    FieldDecList, FieldDecMore, IdList, IdMore,
    VarDec, VarDeclaration, VarDecList, VarDecMore,
    VarIdList, VarIdMore, ProcDec, ProcDeclaration,
    ProcDecMore, ProcName, ParamList, ParamDecList,
    ParamMore, Param, FormList, FidMore,
    ProcDecPart, ProcBody, ProgramBody, StmList,
    StmMore, Stm, AssCall, AssignmentRest,
    ConditionalStm, StmL, LoopStm, InputStm,
    InVar, OutputStm, ReturnStm, CallStmRest,
    ActParamList, ActParamMore, RelExp, OtherRelE,
    Exp, OtherTerm, Term, OtherFactor,
    Factor, Variable, VariMore, FieldVar,
    FieldVarMore, CmpOp, AddOp, MultOp
} NonTerminal; // 非终极符

typedef LexType Terminal;

struct TreeNode;

typedef struct _ExpNode
{
    int NTflag;//终极符？非终极 0:1
    int type;//种类
} ExpNode;

typedef std::vector<ExpNode*> Expression;

extern Expression Express[110];
extern std::set<LexType> Predict[110];

ExpNode* searchForNode(int lt, int flag);

void initExps();
void InitPredict();

TreeNode * parserecur();

TreeNode* program();

void readToken();
TreeNode* matchToken(LexType tok);

#endif // SYNTAX_H
